package com.lcm.springcloud.controller;

import com.lcm.springcloud.common.ResultBean;
import com.lcm.springcloud.param.PaymentParam;
import com.lcm.springcloud.service.impl.PaymentServiceImpl;
import com.lcm.springcloud.vo.PaymentVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @author: Coder-Lcm
 * @date: 2020/10/26 17:10
 */
@RestController
@Slf4j
@RequestMapping("/payment")
public class PaymentController {

    @Autowired
    PaymentServiceImpl paymentService;

    @Value("${server.port}")
    private String serverPort;


    @PostMapping("/add")
    public ResultBean addPayment(@RequestBody PaymentParam payment) {
        boolean ok = paymentService.addPayment(payment);
        if (ok){
            return new ResultBean(200, "添加成功！, serverPort" + serverPort);
        }
        return new ResultBean(444, "插入数据库失败！");
    }

    @GetMapping("/{id}")
    public ResultBean<PaymentVO> findById(@PathVariable("id") @NotNull @Min(1) Long id) {
        ResultBean<PaymentVO> bean = new ResultBean<>(200, "查询成功！, serverPort" + serverPort);
        PaymentVO result = paymentService.findById(id);
        bean.setData(result);
        return bean;
    }

    @GetMapping("/lb")
    public String getPaymentLB(){
        return serverPort;
    }

}
